<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>login</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="static/css/layui.css" media="all">
</head>
<body bgcolor="#faf5f5">

<ul class="layui-nav layui-bg-cyan">
    <li class="layui-nav-item"><a href="/sports">运动会管理系统</a></li>
</ul>


<div class="layui-container fly-marginTop" STYLE="background-color: white">
    <div class="fly-panel fly-panel-user" pad20="">
        <div class="layui-tab layui-tab-brief" lay-filter="user">
            <ul class="layui-tab-title">
                <li class="layui-this">修改密码</li>
            </ul>
            <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form layui-form-pane">
                        <form method="post" action="user/login">

                            <div class="layui-form-item"><label for="L_pass" class="layui-form-label">旧密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_pass" name="pwd"
                                           required="" lay-verify="pwd"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item"><label for="N_pass1" class="layui-form-label">新密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="N_pass1" name="pwd_new1"
                                           required="" lay-verify="pwd_new1"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item"><label for="N_pass2" class="layui-form-label">重新输入新密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="N_pass2" name="pwd_new2"
                                           required="" lay-verify="pwd_new2"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">确认修改</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="div1"></div>


<script th:src="@{static/layui.js}" charset="utf-8"></script>
<script th:src="@{static/jquery.js}"></script>

<script>
    //Demo
    layui.use('form', function () {
        var form = layui.form;
        var $ = layui.jquery;

        //自定义验证规则
        form.verify({

            pwd: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , pwd_new1: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , pwd_new2: function () {
                if ($("#N_pass1").val() != $("#N_pass2").val()) {
                    return "两次密码不一致";
                }
            }
        });

        //监听提交
        form.on('submit(formDemo)', function (data) {
            $.ajax({
                url: "user/rePassword",
                contentType: "application/json",
                type: 'POST',
                data: JSON.stringify(data.field),
                dataType: 'text',
                async: false,
                cache: false,
                success: function (result) {
                    if (result == "success") {
                        window.location.href = "/sports";
                    } else {
                        layer.msg(result)
                    }
                },
                error: function (e) {
                    layer.msg("服务器好像出了问题，请稍后再试");
                }
            });
            return false;
        });
    });
</script>

</body>
</html>